package com.fuze.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuze.domain.dto.ContractQueryDTO;
import com.fuze.domain.dto.DataGridView;
import com.fuze.domain.dto.ServiceFeeContractDTO;
import com.fuze.domain.model.ServiceFeeContract;
import com.fuze.mapper.ServiceFeeContractMapper;
import com.fuze.service.ServiceFeeContractService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;

/**
 * @author sepc_
 * @date 5/19/2021 14:55
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class ServiceFeeContractServiceImpl implements ServiceFeeContractService {

    final ServiceFeeContractMapper serviceFeeContractMapper;

    @Override
    public DataGridView queryByType(ContractQueryDTO queryDTO) {
        Page<ServiceFeeContract> page = new Page<>(queryDTO.getPageNum(), queryDTO.getPageSize());
        this.serviceFeeContractMapper.selectPage(page, null);
        return new DataGridView(page.getTotal(), page.getRecords());
    }

    @Override
    public ServiceFeeContract findById(Integer id) {
        return this.serviceFeeContractMapper.selectById(id);
    }

    @Override
    public int add(ServiceFeeContractDTO serviceFeeContractDTO) {
        ServiceFeeContract contract = new ServiceFeeContract();
        BeanUtils.copyProperties(serviceFeeContractDTO, contract);
        return this.serviceFeeContractMapper.insert(contract);
    }

    @Override
    public int update(ServiceFeeContractDTO serviceFeeContractDTO) {
        ServiceFeeContract contract = new ServiceFeeContract();
        BeanUtils.copyProperties(serviceFeeContractDTO, contract);
        return this.serviceFeeContractMapper.updateById(contract);
    }

    @Override
    public int delete(Integer[] ids) {
        return this.serviceFeeContractMapper.deleteBatchIds(Arrays.asList(ids));
    }
}
